package com.fix.day2aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

/**
 * 切面
 * @author FX_PC
 *
 */
@Component
@Aspect
public class MamAspect {
	
	/*
	@Before("execution(* com.fix.day2aop..*.eat*(..))")
	public void washHand(JoinPoint jp) {
		System.out.println("---->妈妈说。饭前要洗手");
		System.out.println("类名：" + jp.getTarget().getClass().getName());
        System.out.println("方法名：" + jp.getSignature().getName());
        System.out.println("参数值：" + jp.getArgs()[0]);
        System.out.println("======================================");
	}
	
	@After("execution(* com.fix.day2aop..*.eat*(..))")
	public void washDishes() {
		System.out.println("---->妈妈说---饭后要洗碗");
	}
	
	
	//有异常进入此方法
	@AfterThrowing(value="execution(* com.fix.day2aop..*.eat*(..))",throwing="ex")
	void hasException(Exception ex){
		System.out.println("妈妈说，快跑发生了异常"+ex.getMessage());
	}
	*/
	
	@Around("execution(* com.fix.day2aop..*.eat*(..))")
	public void hello(ProceedingJoinPoint pjp) {
		//执行目标方法
		try {
			System.out.println("这里写前置通知");
			pjp.proceed();
			System.out.println("这里写后置通知");
		} catch (Throwable e) {
			e.printStackTrace();
			System.out.println("这里写异常通知");
		}
	}
	
	
}
